<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
  <script>
    function User(name,age){
      // 私有化变量
      let data = {name,age}
      // 私有化方法
      let inf = function(){
        return data.age>20?'老年':'青年'
      }
      // 公共的方法
      this.show = function(){
        console.log(data.name+inf())
      }
    }
    let w = new User("tom",22)
    w.show()
    
  </script>
</html>